﻿using System;
using System.Web;
using MyHealthByDesign.DataAccess.AccountDA;
using MyHealthByDesign.Helper;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Collections.Specialized;

namespace MyHealthByDesign.Domain
{
    /// <summary>
    /// Description:
    /// Domain class provides business functionality for the website.
    /// 
    /// Author: Sanjeev Shrestha
    /// Date Created: 10/17/2011
    /// 
    /// Other code files referenced:
    /// AccountRespository.cs
    /// 
    /// Regression Test Information:
    /// Domain_Test.cs in project MyHealthByDesign_Test
    /// 
    /// Revision History:
    /// 10/19/2011 Sanjeev Shrestha - Added use of account repository object.
    /// 10/20/2011 Sanjeev Shrestha - Added sending of email functionality.
    /// 10/21/2011 Sanjeev Shrestha - Mail fixes and add user object in session.
    /// 10/27/2011 Sanjeev Shrestha - Added function to check if user is logged in.
    /// 10/28/2011 Mark Servais - Added question retrieval.
    /// 10/30/2011 Mark Servais - Added ability to save answers.
    /// 11/03/2011 Mark Servais - Added discalimer and certification update, certification check,
    ///                             and added retrieval of answers.
    /// 11/03/2011 Sanjeev Shrestha - Added ParQ and AHA logic.
    /// 11/04/2011 Sanjeev Shrestha - Added Health Gram logic.
    /// 11/08/2011 Mark Servais - Made fix to return User @@Identity.
    /// 11/30/2011 Mark Servais - Added administration login logic.
    /// 12/02/2011 Mark Servais - Added IsAdminLoggedIn method logic
    /// 12/03/2011 Mark Servais - Added routines for question maintenance
    /// 12/10/2011 Mark Servais - Added routines for option maintenance
    /// 
    /// Known Faults:
    /// None.
    /// </summary>
    public class Domain
    {
        AccountRepository accountRepository = new AccountRepository();
        
        /// <summary>
        /// IsValidUser - Checks if credentials are valid for login
        /// 
        /// PreConditions:
        /// User must exist in the system
        /// 
        /// PostConditions:
        /// Boolean value based on success of credentials
        /// </summary>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool IsValidUser(string email, string password)
        {
            bool validUser = false;
            var user = accountRepository.GetUser(email, password);

            if (user != null)
            {
                validUser = true;
                HttpContext.Current.Session["User"] = user;
            }
            return validUser;
        }

        /// <summary>
        /// IsValidAdminUser - Checks if credentials are valid for administration login
        /// 
        /// PreConditions:
        /// Administration user must exist in the system
        /// 
        /// PostConditions:
        /// Boolean value based on success of credentials
        /// </summary>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool IsValidAdminUser(string email, string password)
        {
            bool validUser = false;
            var user = accountRepository.GetAdminUser(email, password);

            if ((user != null) && (user.Administrator == "Y"))
            {
                validUser = true;
                HttpContext.Current.Session["Admin"] = user;
            }
            return validUser;
        }

        /// <summary>
        /// SendEmail - send password through email
        /// 
        /// PreConditions:
        /// User must exist in the system
        /// 
        /// PostConditions:
        /// Boolean value based on success of email send
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public bool SendEmail(string email)
        {
            bool isSuccess = false;
            string password = accountRepository.GetPassword(email);

            try
            {
                if (!string.IsNullOrWhiteSpace(password))
                {
                    var mail = new Mail();
                    mail.SendEmailAddress(email, password);
                    isSuccess = true;
                }
                else
                {
                    //no action needed since IsSuccess is false by default
                }
            }
            catch (Exception ex)
            {
                //no action needed since IsSuccess is false by default
            }

            return isSuccess;
        }

        /// <summary>
        /// IsEmailRegistered - check if email is registered
        /// 
        /// PreConditions:
        /// User must exist in the system
        /// 
        /// PostConditions:
        /// Boolean value based on success of email check
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public bool IsEmailRegistered(string email)
        {
            bool isRegistered = true;
            string password = accountRepository.GetPassword(email);

            if(string.IsNullOrWhiteSpace(password))
            {
                isRegistered = false;
            }

            return isRegistered;
        }

        /// <summary>
        /// RegisterUser - registers new user into the system
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Boolean value based on success of registration
        /// </summary>
        /// <param name="lastname"></param>
        /// <param name="firstname"></param>
        /// <param name="birthDate"></param>
        /// <param name="city"></param>
        /// <param name="zipCode"></param>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <param name="mobile"></param>
        /// <param name="textFlag"></param>
        /// <param name="sex"></param>
        /// <param name="ethnicity"></param>
        /// <returns></returns>
        public bool RegisterUser(string lastname, string firstname, string birthDate, string city, string state, string zipCode, string email, string password, string mobile, string textFlag, string sex, string ethnicity)
        {
            bool success = false;
           
            int insertId = accountRepository.RegisterUser(lastname, firstname, birthDate, city, state, zipCode, email, password, mobile, textFlag, sex, ethnicity);
                
            if(insertId > 0)
            {
                success = true;
                var user = new User
                               {
                                   UserId = insertId,
                                   Email = email,
                                   Firstname = firstname,
                                   Lastname = lastname,
                                   BirthDate = birthDate,
                                   City = city,
                                   State = state,
                                   ZipCode = zipCode,
                                   Password = password,
                                   MobilePhone = mobile,
                                   Gender = sex,
                                   Ethnicity = ethnicity,
                                   TextFlag = textFlag
                               };

                HttpContext.Current.Session["User"] = user;
            }

            return success;
        }

        /// <summary>
        /// IsUserLoggedIn - checks to see if the user is already logged in
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Boolean value based on success of user login check
        /// </summary>
        /// <returns></returns>
        public bool IsUserLoggedIn()
        {
            bool isLoggedIn = false;
            
            if (HttpContext.Current.Session["User"] != null)
            {
                isLoggedIn = true;
            }

            return isLoggedIn;
        }

        /// <summary>
        /// IsAdminLoggedIn - checks to see if the admin is already logged in
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Boolean value based on success of admin login check
        /// </summary>
        /// <returns></returns>
        public bool IsAdminLoggedIn()
        {
            bool isLoggedIn = false;

            if (HttpContext.Current.Session["Admin"] != null)
            {
                isLoggedIn = true;
            }

            return isLoggedIn;
        }

        /// <summary>
        /// RetrieveQuestions - retrieve the questions for a provided category
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// List of Questions for the category provided
        /// </summary>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public List<Question> RetrieveQuestions(int categoryId)
        {
            return accountRepository.GetQuestions(categoryId);
        }

        /// <summary>
        /// SaveQuestionAnswers - obtain question answer values and save to database
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Boolean value if answer additions were successful
        /// </summary>
        /// <param name="contentPlaceHolder"></param>
        /// <returns></returns>
        public bool SaveQuestionAnswers(ContentPlaceHolder contentPlaceHolder)
        {
            try
            {
                if (HttpContext.Current.Session["User"] != null)
                {
                    List<QuestionAnswer> lstQuestionAnswers = new List<QuestionAnswer>();
                    
                    User user = (User)HttpContext.Current.Session["User"];
                    int nCount = 0;


                    List<Question> lstQuestions = (List<Question>) HttpContext.Current.Session["Questions"];

                    foreach (Question question in lstQuestions)
                    {
                        Dictionary<Question, NameValueCollection> returnValue = question.RetrieveQuestionValues(contentPlaceHolder);
                        foreach (var item in returnValue)
                        {
                            NameValueCollection nvc = item.Value;

                            for (nCount = 0; nCount < nvc.Count; nCount++)
                            {
                                QuestionAnswer questionAnswer = new QuestionAnswer();
                                questionAnswer.QuestionId = question.Id;
                                questionAnswer.UserId = user.UserId;
                                questionAnswer.FieldName = nvc.GetKey(nCount);
                                questionAnswer.FieldValue = nvc.Get(nCount);

                                lstQuestionAnswers.Add(questionAnswer);
                            }

                        }
                    }

                   // insert to database
                   return accountRepository.AnswersRecorded(lstQuestionAnswers);
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {
                return false;
            }
        }

        /// <summary>
        /// UserCertification - Save certification date to database for user
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Boolean value if certification date update were successful
        /// </summary>
        /// <returns></returns>
        public bool UserCertification()
        {
            try
            {
                User user = (User)HttpContext.Current.Session["User"];
                return accountRepository.CertificationDateUpdated(user);
            }
            catch (Exception)
            {
                return false;
            }

        }

        /// <summary>
        /// UserDisclaimer - Save disclaimer date to database for user
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Boolean value if disclaimer date update were successful
        /// </summary>
        /// <returns></returns>
        public bool UserDisclaimer()
        {
            try
            {
                User user = (User)HttpContext.Current.Session["User"];
                return accountRepository.DisclaimerDateUpdated(user);
            }
            catch (Exception)
            {
                return false;
            }

        }

        /// <summary>
        /// UserAnswersCertified - Check to see if user has certification date
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Boolean value if certification date check was successful
        /// </summary>
        /// <returns></returns>
        public bool UserAnswersCertified()
        {
            try
            {
                User user = (User)HttpContext.Current.Session["User"];
                return accountRepository.HasUserCertifiedAnswers(user);
            }
            catch (Exception)
            {
                return false;
            }

        }
        
        /// <summary>
        /// IsEligibileForParq - Check to see if user needs Parq
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Boolean value if ParQ is needed
        /// </summary>
        /// <returns></returns>
        public bool IsEligibileForParq()
        {
            bool isEligible = false;

            if (HttpContext.Current.Session["User"] != null)
            {
                var user = (User)HttpContext.Current.Session["User"];
                var birthDate = Convert.ToDateTime(user.BirthDate);
                if (GetAge(birthDate) <= 40)
                {
                    isEligible = true;
                }
            }

            return isEligible;
        }

        /// <summary>
        /// GetAge - Retreive user age
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Integer value of the user age
        /// </summary>
        /// <param name="birthDate"></param>
        /// <returns></returns>
        public int GetAge(DateTime birthDate)
        {
            // cache the current time
            var now = DateTime.Today; // today is fine, don't need the timestamp from now

            // get the difference in years
            int years = now.Year - birthDate.Year;

            // subtract another year if we're before the birth day in the current year
            if (now.Month < birthDate.Month || (now.Month == birthDate.Month && now.Day < birthDate.Day))
                --years;

            return years;
        }

        /// <summary>
        /// GetQuestionAnswer - Get question answer for user by field name
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// QuestionAnswer object for field name
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public QuestionAnswer GetQuestionAnswer(string fieldName)
        {
            try
            {
                User user = (User)HttpContext.Current.Session["User"];
                return accountRepository.GetAnswer(user.UserId, fieldName);
            }
            catch (Exception)
            {
                return null;
            }
        }

        /// <summary>
        /// GetUserAnswers - Get all question answesr for user
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Collection of QuestionAnswer objects
        /// </summary>
        /// <returns></returns>
        public List<QuestionAnswer> GetUserAnswers()
        {
            try
            {
                User user = (User)HttpContext.Current.Session["User"];
                return accountRepository.GetUserAnswers(user.UserId);
            }
            catch (Exception)
            {
                return null;
            }
        }

        /// <summary>
        /// SetInitialQuestionAnswers - set the initial question answer values for the form
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// The field values will have their values set from the database
        /// </summary>
        /// <param name="contentPlaceHolder"></param>
        public void SetInitialQuestionAnswers(ContentPlaceHolder contentPlaceHolder)
        {
            try
            {
                if (HttpContext.Current.Session["User"] != null)
                {
                    User user = (User)HttpContext.Current.Session["User"];
                    int nCount = 0;

                    List<QuestionAnswer> lstQuestionAnswers = GetUserAnswers();
                    NameValueCollection nvcAnswers = new NameValueCollection();
                    
                    foreach (QuestionAnswer questionAnswer in lstQuestionAnswers)
                    {
                        nvcAnswers.Add(questionAnswer.FieldName, questionAnswer.FieldValue);
                    }

                    List<Question> lstQuestions = (List<Question>) HttpContext.Current.Session["Questions"];

                    foreach (Question question in lstQuestions)
                    {
                        question.SetInitialQuestionAnswer(nvcAnswers, contentPlaceHolder);
                    }
                    
                }
               
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// GetUserHealthMeasurement - get health gram information
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// returns HelathMeasurmnet class with health gram information
        /// </summary>
        /// <param name="user">Logged in user</param>
        /// <returns>Health Measurement of user</returns>
        public HealthMeasurement GetUserHealthMeasurement(User user)
        {
            var healthMeasurement = new HealthMeasurement();

            if (accountRepository.GetUserAnswers(user.UserId) != null)
            {
                var answerList = accountRepository.GetUserAnswers(user.UserId);
                string heightFt = string.Empty;
                string heightIn = string.Empty;

                foreach (var questionAnswer in answerList)
                {
                    if (questionAnswer.FieldName == "tbWeight" && questionAnswer.FieldValue != null && questionAnswer.FieldValue.Trim().Length > 0)
                    {
                        healthMeasurement.Weight = Convert.ToDouble(questionAnswer.FieldValue);
                    }

                    if (questionAnswer.FieldName == "tbHeightft" && questionAnswer.FieldValue != null && questionAnswer.FieldValue.Trim().Length > 0)
                    {
                        heightFt = questionAnswer.FieldValue;
                    }

                    if (questionAnswer.FieldName == "tbHeightin" && questionAnswer.FieldValue != null && questionAnswer.FieldValue.Trim().Length > 0)
                    {
                        heightIn = questionAnswer.FieldValue;
                    }

                    if (questionAnswer.FieldName == "tbBMI" && questionAnswer.FieldValue != null && questionAnswer.FieldValue.Trim().Length > 0)
                    {
                        healthMeasurement.Bmi = Convert.ToDouble(questionAnswer.FieldValue);
                    }

                    if (questionAnswer.FieldName == "tbWaistCircIn" && questionAnswer.FieldValue != null && questionAnswer.FieldValue.Trim().Length > 0)
                    {
                        healthMeasurement.WaistMeasurement = Convert.ToDouble(questionAnswer.FieldValue);
                    }

                    if (questionAnswer.FieldName == "tbWaistCircCm" && questionAnswer.FieldValue != null && questionAnswer.FieldValue.Trim().Length > 0)
                    {
                    }

                    if (questionAnswer.FieldName == "tbBPSystolic" && questionAnswer.FieldValue != null && questionAnswer.FieldValue.Trim().Length > 0)
                    {
                        healthMeasurement.SystolicBp = Convert.ToInt32(questionAnswer.FieldValue);
                    }

                    if (questionAnswer.FieldName == "tbBPDiastolic" && questionAnswer.FieldValue != null && questionAnswer.FieldValue.Trim().Length > 0)
                    {
                        healthMeasurement.DiastoliBp = Convert.ToInt32(questionAnswer.FieldValue);
                    }

                    if (questionAnswer.FieldName == "tbTotalCholestorol" && questionAnswer.FieldValue != null && questionAnswer.FieldValue.Trim().Length > 0)
                    {
                        healthMeasurement.TotalCholesterol = Convert.ToInt32(questionAnswer.FieldValue);
                    }

                    if (questionAnswer.FieldName == "tbBloodGlucose" && questionAnswer.FieldValue != null && questionAnswer.FieldValue.Trim().Length > 0)
                    {
                        healthMeasurement.BloodGlucose = Convert.ToInt32(questionAnswer.FieldValue);
                    }
                }

                if (!string.IsNullOrEmpty(heightFt) && !string.IsNullOrEmpty(heightIn))
                {
                    healthMeasurement.Height = Convert.ToDouble(heightFt.Trim() + "." + heightIn.Trim());
                }
                else if (!string.IsNullOrEmpty(heightFt))
                {
                    healthMeasurement.Height = Convert.ToDouble(heightFt.Trim());
                }
                else if (!string.IsNullOrEmpty(heightIn))
                {
                    healthMeasurement.Height = Convert.ToDouble(heightIn.Trim());
                }
            }

            return healthMeasurement;
        }

        /// <summary>
        /// IsRiskQuestionAnswered - check if user answered at least one question under each section
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// returns true if user has selected atleast one quesiton's answer under each questionnaire seciton else false
        /// </summary>
        /// <param name="contentPlaceHolder"></param>
        /// <returns>true if user has selected atleast one quesiton's answer under each questionnaire seciton else false</returns>
        public bool IsRiskQuestionAnswered(ContentPlaceHolder contentPlaceHolder)
        {
            try
            {
                if (HttpContext.Current.Session["User"] != null)
                {
                    var lstQuestions = (List<Question>)HttpContext.Current.Session["Questions"];

                    foreach (Question question in lstQuestions)
                    {
                        bool valid = false;
                        Dictionary<Question, NameValueCollection> returnValue = question.RetrieveQuestionValues(contentPlaceHolder);
                        foreach (var item in returnValue)
                        {
                            NameValueCollection nvc = item.Value;

                            int nCount = 0;
                            for (nCount = 0; nCount < nvc.Count; nCount++)
                            {
                                if(nvc.Get(nCount) == "True")
                                {
                                    valid = true;
                                    break;
                                }
                            }

                            if(!valid)
                            {
                                return false;
                            }
                        }
                    }

                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {
                return false;
            }
        }

        /// <summary>
        /// GetCategories - Get all question categories
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Collection of QuestionCategory objects
        /// </summary>
        /// <returns></returns>
        public List<QuestionCategory> GetCategories()
        {
            try
            {
                return accountRepository.GetCategories();
            }
            catch (Exception)
            {
                return null;
            }
        }

        /// <summary>
        /// InsertCategory - insert category to the database
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Category is added to the database
        /// </summary>
        /// <returns></returns>
        public bool InsertCategory(string categoryDescription)
        {
            try
            {
                return (accountRepository.InsertCategory(categoryDescription) != 0);
            }
            catch (Exception)
            {
                return false;
            }
        }

        /// <summary>
        /// UpdateCategory - update category to the database
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Category is updated in the database
        /// </summary>
        /// <returns></returns>
        public bool UpdateCategory(int categoryId, string categoryDescription)
        {
            try
            {
                return accountRepository.UpdateCategory(categoryId, categoryDescription);
            }
            catch (Exception)
            {
                return false;
            }
        }

        /// <summary>
        /// DeleteCategory - delete category in the database
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Category is deleted in the database
        /// </summary>
        /// <returns></returns>
        public bool DeleteCategory(int categoryId)
        {
            try
            {
                return accountRepository.DeleteCategory(categoryId);
            }
            catch (Exception)
            {
                return false;
            }
        }

        /// <summary>
        /// RetrieveQuestion - retrieve the question for a provided question ID
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Question provided
        /// </summary>
        /// <param name="questionId"></param>
        /// <returns></returns>
        public Question RetrieveQuestion(int questionId)
        {
            return accountRepository.GetQuestionById(questionId);
        }

        /// <summary>
        /// UpdateQuestionCore - update the core fields of a question
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Question is updated in the database
        /// </summary>
        /// <param name="question"></param>
        /// <returns></returns>
        public bool UpdateQuestionCore(Question question)
        {
            return accountRepository.UpdateQuestionCore(question.Id, question.Category, question.SortOrder,
                                                        question.DisplayType,
                                                        question.ContentLabel, question.FieldCSS, question.FieldSuffix,
                                                        question.FieldHelpText, question.FieldHelpURL);
        }

        /// <summary>
        /// UpdateQuestionStatus - update question status in the database
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Question status is updated in the database
        /// </summary>
        /// <returns></returns>
        public bool UpdateQuestionStatus(int questionId)
        {
            try
            {
                return accountRepository.UpdateQuestionStatus(questionId);
            }
            catch (Exception)
            {
                return false;
            }
        }

        /// <summary>
        /// UpdateQuestionStatusByValue - update question status in the database
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Question status is updated in the database
        /// </summary>
        /// <returns></returns>
        public bool UpdateQuestionStatusByValue(int questionId, bool questionActive)
        {
            try
            {
                return accountRepository.UpdateQuestionStatusByValue(questionId, questionActive);
            }
            catch (Exception)
            {
                return false;
            }
        }

        /// <summary>
        /// InsertQuestionCore - insert the core fields of a question
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Question is inserted in the database; identity is returned
        /// </summary>
        /// <param name="question"></param>
        /// <returns></returns>
        public int InsertQuestionCore(Question question)
        {
            return accountRepository.InsertQuestionCore(question.Category, question.SortOrder,
                                                        question.DisplayType, question.Name,
                                                        question.ContentLabel, question.FieldCSS, question.FieldSuffix,
                                                        question.FieldHelpText, question.FieldHelpURL);
        }

        /// <summary>
        /// RetrieveQuestionOptions - retrieve the options for a provided question
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// List of QuestionOptions for the question provided
        /// </summary>
        /// <param name="questionId"></param>
        /// <returns></returns>
        public List<QuestionOption> RetrieveQuestionOptions(int questionId)
        {
            return accountRepository.GetOptionsByQuestionId(questionId);
        }

        /// <summary>
        /// UpdateOption - update an option of a question
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Option is updated in the database
        /// </summary>
        /// <param name="questionOption"></param>
        /// <returns></returns>
        public int UpdateOption(QuestionOption questionOption)
        {
            return accountRepository.UpdateOption(questionOption);
        }

        /// <summary>
        /// InsertQuestionOptionCore - inserts an option of a question
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Option is inserted in the database
        /// </summary>
        /// <param name="questionOption"></param>
        /// <returns></returns>
        public int InsertQuestionOptionCore(QuestionOption questionOption, int questionId)
        {
            return accountRepository.InsertOptionCore(questionOption, questionId);
        }

        /// <summary>
        /// UpdateOptionStatusByValue - update option status in the database
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Option status is updated in the database
        /// </summary>
        /// <returns></returns>
        public bool UpdateOptionStatusByValue(int optionId, bool optionActive)
        {
            try
            {
                return accountRepository.UpdateOptionStatusByValue(optionId, optionActive);
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}